import Page
from Page import Shop
from Base.Base import Base
from selenium.webdriver.common.by import By


class ShopIndexPage(Base):
    """
    奔腾商城首页

    个性主题的语音音色页、全息形象页、整车音效页可复用此页
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 系统主题标题
        self.index_system_theme_text = (By.XPATH, Page.TEXT.format("系统主题"))

        # 语音音色标题
        self.index_voice_title_text = (By.XPATH, Page.TEXT.format("语音音色"))

        # 我的积分总数
        self.index_my_coin_text = (By.XPATH, Shop.RESOURCE_ID.format("tv_main_mine_score_num"))

        # 个性主题tab
        self.index_personal_theme_text = (By.XPATH, Page.TEXT.format("个性主题"))

        # 全息形象tab
        self.index_3d_image_text = (By.XPATH, Page.TEXT.format("全息形象"))

        # 整车音效tab
        self.index_car_voice_text = (By.XPATH, Page.TEXT.format("整车音效"))

        # 流量商城tab
        self.index_network_shop_text = (By.XPATH, Page.TEXT.format("流量商城"))

        # 我的购买tab
        self.index_my_purchase_text = (By.XPATH, Page.TEXT.format("我的购买"))

        # 综合排序
        self.index_sort_all_text = (By.XPATH, Page.TEXT.format("综合"))

        # 销量排序
        self.index_sort_sales_text = (By.XPATH, Page.TEXT.format("销量"))

        # 最近上架排序
        self.index_sort_new_text = (By.XPATH, Page.TEXT.format("最近上架"))

        # 积分价排序
        self.index_sort_coin_text = (By.XPATH, Page.TEXT.format("积分价"))

        # 现金价排序
        self.index_sort_cash_text = (By.XPATH, Page.TEXT.format("现金价"))

        # 首页列表的封面, 默认取1
        self.index_list_cover_img = (By.XPATH, Shop.index_list_cover_img.format(1))

        # 首页列表的名称, 默认取1
        self.index_list_title_text = (By.XPATH, Shop.index_list_title_text.format(1))

        # 首页列表的下载次数, 默认取1
        self.index_list_download_times_text = (By.XPATH, Shop.index_list_download_times_text.format(1))

        # 首页列表的在售车币价格, 默认取1
        self.index_list_coin_price_text = (By.XPATH, Shop.index_list_coin_price_text.format(1))

        # 首页列表的在售现金价格, 默认取1
        self.index_list_cash_price_text = (By.XPATH, Shop.index_list_cash_price_text.format(1))

        # 首页列表的购买/下载按钮, 默认取1
        self.index_list_buy_btn = (By.XPATH, Shop.index_list_buy_btn.format(1))

        # 首页列表的试用按钮, 默认取1
        self.index_list_try_btn = (By.XPATH, Shop.index_list_try_btn.format(1))

    def get_my_coin(self):
        """
        获取`我的积分`

        :return:
        """
        return self.find_element_o(self.index_my_coin_text)

    def get_list_cover(self, index=1):
        """
        获取列表中指定索引的封面

        :param index: 索引值, 从1开始取
        :return:
        """
        self.index_list_cover_img = (By.XPATH, Shop.index_list_cover_img.format(index - 1))
        return self.find_element_o(self.index_list_cover_img)

    def get_list_title(self, index=1):
        """
        获取列表中指定索引的名称

        :param index: 索引值, 从1开始取
        :return:
        """
        self.index_list_title_text = (By.XPATH, Shop.index_list_title_text.format(index - 1))
        return self.find_element_o(self.index_list_title_text)

    def get_list_download_time(self, index=1):
        """
        获取列表中指定索引的下载次数

        :param index: 索引值, 从1开始取
        :return:
        """
        self.index_list_download_times_text = (By.XPATH, Shop.index_list_download_times_text.format(index - 1))
        return self.find_element_o(self.index_list_download_times_text)

    def get_list_coin_price(self, index=1):
        """
        获取列表中指定索引的车币价格

        :param index: 索引值, 从1开始取
        :return:
        """
        self.index_list_coin_price_text = (By.XPATH, Shop.index_list_coin_price_text.format(index - 1))
        return self.find_element_o(self.index_list_coin_price_text)

    def get_list_cash_price(self, index=1):
        """
        获取列表中指定索引的现金价格

        :param index: 索引值, 从1开始取
        :return:
        """
        self.index_list_cash_price_text = (By.XPATH, Shop.index_list_cash_price_text.format(index - 1))
        return self.find_element_o(self.index_list_cash_price_text)

    def get_list_buy(self, index=1):
        """
        获取列表中指定索引的购买按钮

        :param index: 索引值, 从1开始取
        :return:
        """
        self.index_list_buy_btn = (By.XPATH, Shop.index_list_buy_btn.format(index - 1))
        return self.find_element_o(self.index_list_buy_btn)

    def get_list_try(self, index=1):
        """
        获取列表中指定索引的试用按钮

        :param index: 索引值, 从1开始取
        :return:
        """
        self.index_list_try_btn = (By.XPATH, Shop.index_list_try_btn.format(index - 1))
        return self.find_element_o(self.index_list_try_btn)

    def click_system_theme(self):
        """
        点击`系统主题`tab

        :return:
        """
        self.click_element(self.index_system_theme_text)

    def click_voice_title(self):
        """
        点击`语音音色`tab

        :return:
        """
        self.click_element(self.index_voice_title_text)

    def click_personal_theme(self):
        """
        点击左侧的`个性主题`tab

        :return:
        """
        self.click_element(self.index_personal_theme_text)

    def click_3d_image(self):
        """
        点击左侧的`全息形象`tab

        :return:
        """
        self.click_element(self.index_3d_image_text)

    def click_car_voice(self):
        """
        点击左侧的`整车音效`tab

        :return:
        """
        self.click_element(self.index_car_voice_text)

    def click_network_shop(self):
        """
        点击左侧的`流量商城`tab

        :return:
        """
        self.click_element(self.index_network_shop_text)

    def click_my_purchase(self):
        """
        点击左侧的`我的购买`tab

        :return:
        """
        self.click_element(self.index_my_purchase_text)

    def click_list_buy(self, index=1):
        """
        点击指定索引值的购买/下载按钮

        :param index: 索引值
        :return:
        """
        self.index_list_buy_btn = (By.XPATH, Shop.index_list_buy_btn.format(index - 1))
        self.click_element(self.index_list_buy_btn)

    def click_list_try(self, index=1):
        """
        点击指定索引值的试用按钮

        :param index: 索引值
        :return:
        """
        self.index_list_try_btn = (By.XPATH, Shop.index_list_try_btn.format(index - 1))
        self.click_element(self.index_list_try_btn)
